/**
 * Created by Administrator on 2017/7/27.
 */
$(function () {
   
        FastClick.attach(document.body);
 
    function getQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if ( r != null ){
            return decodeURI(r[2]);
        }else{
            return null;
        }
    };
    var name=getQueryString("name");
    console.log(name);
    var index =getQueryString("id")
    var sPatientHGuid=getQueryString("sPatientHGuid");
    var sCollectionBillGuid=getQueryString("index");
    $(".spinner").show();
    $.ajax({
        url:"http://www.jzxchina.cn/M_AjaxData/M_PatientInfoAjax/GetSZCollectionBillValue",
        data:{"sPatientHGuid":sPatientHGuid,"sCollectionBillGuid":sCollectionBillGuid},
        dataType: "JSONP",
        success:function (data) {

            console.log(data);
            $(".Hospital-examine").find("span").text(name)
            console.log(data.length);

            var yearNum = [];
            $(data).each(function(i, v){
                yearNum.push(this.sBatchGuid);
            })
            console.log(yearNum);
            var years = {};

            for (var i = 0; i < yearNum.length; i++){
                if(!years[yearNum[i]]) {
                    years[yearNum[i] + ''] = [];
                }
            };
            console.log(years);
            $(data).each(function(i, v){
                for (var j in years) {
                    if(v.sBatchGuid == j){
                        years[v.sBatchGuid].push(v);
                        break;
                    }
                }
            });

            var html=""
            for (var k in years) {
              console.log({item: years[k]})
                html+= template("temUl", {item:years[k]});
            };
                $("#chechUl").prepend(html);
            $("#num.mui-navigate-right").each(function (i,v) {
                if($(v).data("abc")==0){
                    $(this).find("div:nth-of-type(2)>span").css("color","green");
                    $(this).find("div:nth-of-type(2)>img").remove();
                    $(this).prev("span").remove();
                };
                if($(v).data("abc")==1){
                    $(this).find("div:nth-of-type(2)>span").css("color","red");
                }
                if($(v).data("abc")==2){
                    $(this).find("div:nth-of-type(2)>img").css({"transform":"rotate(180deg)","margin-top":"-.08rem"});
                    $(this).find("div:nth-of-type(2)>span").css("color","red");
                };
                if($(v).data("abc")==3){
                    $(this).find("div:nth-of-type(2)>img").remove();
                    $(this).find("div:nth-of-type(2)>span").css("color","red");
                }
            });
            $(".Hospital-normal").on("click", function () {
                $(this).prev("div").fadeToggle();
            });
            $(".spinner").hide();
        }
    });

    $(".icon-zuo").attr("href","historySheet.html?index="+index);
//	$(".icon-zuo").click(function(){
//		history.go(-1);
//	})

})